package demo4

import (
	"net/http"

	demo4srcmain "gitee.com/xukun17/starter-gin-demo/demo4/src/main"
	ginstarter "github.com/bitwormhole/starter-gin"
	"github.com/bitwormhole/starter-gin/glass"
	"github.com/bitwormhole/starter/application"
	"github.com/gin-gonic/gin"
)

func theAPIs(ec glass.EngineConnection) error {
	ec = ec.RequestMapping("/api/demo4.v1/video")
	ec.Handle(http.MethodGet, "", doGetVideoList)
	ec.Handle(http.MethodGet, ":id", doGetVideoData)
	return nil
}

func ExportModule() application.Module {

	devtools := ginstarter.ModuleWithDevtools()

	smb := ginstarter.SimpleModule()
	smb.Name("demo4模块").Version("第一版").Revision(1)
	smb.Resources(demo4srcmain.ExportResources())
	smb.Dependency(devtools)
	smb.RegisterControllerFunc(theAPIs)

	return smb.Create()
}

func doGetVideoList(c *gin.Context) {

	// ginstarter.

	c.JSON(200, gin.H{
		"get": "video-list",
	})
}

func doGetVideoData(c *gin.Context) {
	c.JSON(200, gin.H{
		"get": "video-data",
	})
}
